using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Mapping.Attributes;
using Persistance.Model;
using Lib;
using System.Collections;

namespace Persistance.BLL
{
    public class ProblemCausesManagement
    {

        public static ProblemCauses getConfirmedCause(Persistance.Model.Problem problem)
        {
            ISession sess = Persistor.CurrentSession;
            try
            {
                IQuery q = sess.CreateQuery("from ProblemCauses pc where pc.IsConfirmed = 1 and pc.Problem.ProblemID = :ID");
                q.SetInt32("ID", problem.ProblemID);
                List<ProblemCauses> results = (List<ProblemCauses>)q.List<ProblemCauses>();

                if (results.Count > 0)
                    return results[0];

                else
                    return null;
            }
            catch (Exception e)
            {
                throw new Exception("Error Reteiving Confirmed Cause. Has the Problem been saved?: ", e);
            }
        }
    }
}
